/**
 * Created by HuQiang on 2017/8/3.
 */
import React from 'react';
import {hashHistory} from 'react-router';
import {Button, Card} from 'antd';
import 'antd/dist/antd.css';  // or 'antd/dist/antd.less'
require("./Home.css");
require("./HistoryExam.css");
import $ from "jquery";

let h_score = [];
let begin = [];
let exam_type = [];
let dataList = [];
let exam_id = [];
export default class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            user_id: this.props.user_id
        }
    }

    componentWillMount() {
        dataList.length = 0;
        h_score.length = 0;
        begin.length = 0;
        exam_id.length = 0;
        exam_type.length = 0;
        this.fetchData();
    }

    fetchData = () => {
        $.ajax({
            type: "POST",
            url: "http://123.207.214.129:9090/LanOu/getExamHistoryList",
            data: {
                user_id: this.state.user_id
            },
            async: false,
            dataType: "json",
            success: (data) => {
                for (let i = 0; i < data.data.length; i++) {
                    h_score.push(data.data[i].h_score);
                    begin.push(data.data[i].begin);
                    exam_id.push(data.data[i].id);
                    exam_type.push(data.data[i].exam_type);
                    dataList.push(

                        <Card title={exam_type[i]}
                              extra={
                                  <Button style={buttonStyle} type="default" onClick={() => {
                                      hashHistory.push("/ExamDetail/" + exam_id[i]);
                                  }
                                  }>查看详情</Button>
                              }
                              key={i}
                              style={cardStyle}>
                            <p>考试时间:{begin[i]}</p>
                            <p className="score">成绩:{h_score[i]}</p>
                        </Card>

                    );
                }
                console.log(data);
            },
            error: function (e) {
                console.log(e);
            }
        });
    };

    render() {
        return (

            <div>
                <div className="title-history">
                    <p>考试历史</p>
                </div>
                <div>
                {dataList}
                </div>
            </div>
        );
    }
}
const cardStyle = {
    display: 'block',
    width: '95%',
    marginTop: '20px',
    lineHeight:'30px',
    fontSize: '18px'
};
const buttonStyle = {
    display:'block',
    width: '100px',
    bottom:'3px',
};


